<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015-6-16
 * Time: 11:52
 */

namespace doumiaoduo\ueditor\actions;


use yii\base\Action;
use yii\helpers\Json;

class ConfigAction extends Action{

    private $_config;

    public function init(){
        $this->_config=\Yii::$app->params['ueditor'];
        parent::init();
    }

    public function run(){
        return $this->__checkParam();
    }

    private function __checkParam(){
        if (\Yii::$app->request->get("callback")!=null) {
            if (preg_match("/^[\w_]+$/", \Yii::$app->request->get("callback"))) {
                return htmlspecialchars(\Yii::$app->request->get("callback")) . '(' . Json::encode($this->_config) . ')';
            } else {
                return Json::encode(['state'=> 'callback参数不合法']);;
            }
        } else {
            return Json::encode($this->_config);
        }
    }

}